//
//  BZGMixedDevelopmentController.m
//  BZGCode
//
//  Created by coderz on 2019/12/4.
//  Copyright © 2019 coderz. All rights reserved.
//

#import "BZGMixedDevelopmentController.h"

/*
 var reg = /^([\u3000-\u303F]|[\u2E80-\uFE4F]){1}[\S]{7,49}/;

 ^[\\u3000-\\u303F\\u2E80-\\uFE4F]([\\S]*)$
 */

#define KDBankAdress @"^[\u4e00-\u9fa5]{1}([\\S]*)$"

@interface BZGMixedDevelopmentController ()<UITextFieldDelegate>

@property (nonatomic, strong) UISegmentedControl *segControl;

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UITextField *enterField;

@property (nonatomic, strong) UIImageView *imageV;

@end

@implementation BZGMixedDevelopmentController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.url = [NSURL URLWithString:@"https://www.google.cn/?client=safari&channel=iphone_bm"];
//    [self.view addSubview:self.bgView];
//    self.bgView.frame = CGRectMake(99, 99, 202, 42);
    [self.view addSubview:self.segControl];
    self.segControl.frame = CGRectMake(100, 100, 200, 40);
    
    [self.view addSubview:self.enterField];
    self.enterField.frame = CGRectMake(20, 200, self.view.frame.size.width - 40, 30);
    NSLog(@"%@",[UIDevice currentDevice].identifierForVendor.UUIDString);
    
    [self.view addSubview:self.imageV];
    self.imageV.frame = CGRectMake(20, 220, self.view.frame.size.width - 40, 300);
    
    
    self.view.backgroundColor = [UIColor clearColor];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    NSLog(@"-----%ld",(long)[self stringStr:self.enterField.text]);
    
    NSString *str = self.enterField.text;
    [str lengthOfBytesUsingEncoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000)];
    
    NSLog(@"str : %lu",(unsigned long)[str lengthOfBytesUsingEncoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000)]);
    
//    NSLog(@"------%@",[self URLEncodedString:@"北京市东城区#$%&&&*安慧北里小区安园13号楼503"]);
    
//    NSDecimalNumber *useableAmtNum = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%@",@"12.1"]];
//
//    NSDecimalNumber *cashStrNum = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%@",@"12.9"]];
//
//    if ([useableAmtNum compare:cashStrNum] == NSOrderedAscending) {
//        NSLog(@"1");
//    } else if ([useableAmtNum compare:cashStrNum] == NSOrderedSame){
//        NSLog(@"2");
//    } else if ([useableAmtNum compare:cashStrNum] == NSOrderedDescending){
//        NSLog(@"3");
//    }
}

- (NSString *)URLEncodedString:(NSString *)str {
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)str,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    return encodedString;
}

/*
 NSString *str3 = [[NSBundle mainBundle]resourcePath] ;

 NSString *path = [str3 stringByAppendingPathComponent:@"test.html"];

 NSString*htmlstr = [[NSStringalloc]initWithContentsOfFile:pathencoding:NSUTF8StringEncodingerror:nil];

 [webloadHTMLString:htmlstrbaseURL:[[NSBundlemainBundle]bundleURL]];
 */

- (void)selectItem:(UISegmentedControl *)control {
    NSLog(@"1");
}

-(UISegmentedControl *)segControl {
    if (_segControl == nil) {
        _segControl = [[UISegmentedControl alloc] initWithItems:@[@"委托查询",@"成交查询"]];
        _segControl.frame = CGRectMake(65, 16, 375 - 130, 28);
        _segControl.selectedSegmentIndex = 0;
        _segControl.tintColor = [UIColor redColor];
        
        [_segControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
        [_segControl setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
        [_segControl setBackgroundImage:[UIImage imageWithColor:[UIColor redColor]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
        [_segControl setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        

         [_segControl addTarget:self action:@selector(selectItem:) forControlEvents:UIControlEventValueChanged];
        
        
        _segControl.layer.borderColor = [UIColor redColor].CGColor;
        _segControl.layer.borderWidth = 1;
        _segControl.backgroundColor = [UIColor clearColor];
//        _segControl.layer.cornerRadius = 20;
        _segControl.layer.masksToBounds = YES;

    }
    return _segControl;
}

-(UIView *)bgView {
    if (_bgView == nil) {
        _bgView = [[UIView alloc] init];
//        _bgView.frame = CGRectMake(65 - 0.5, 16 - 0.5, 375 - 130 + 2, 230);
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.masksToBounds = YES;
        _bgView.layer.borderWidth = 1;
        _bgView.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor redColor]);
    }
    return _bgView;
}

-(UITextField *)enterField {
    
    if (_enterField == nil) {
        _enterField = [[UITextField alloc] init];
        _enterField.placeholder = @"请输入字符串";
        _enterField.clearButtonMode = UITextFieldViewModeAlways;
    
        _enterField.delegate = self;
    }
    return _enterField;
}

- (BOOL)checkAddressOnly:(NSString *)text
{
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",KDBankAdress];
    return [pred evaluateWithObject:text];
}

-(NSInteger)stringStr:(NSString *)str {
    NSUInteger  character = 0;
    for(int i=0; i< [str length];i++){
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff){ //判断是否为中文
            character += 2;
        }else{
            character +=1;
        }
    }
    return character;
}

-(UIImageView *)imageV {
    if (_imageV == nil) {
        _imageV = [[UIImageView alloc] init];
        _imageV.image = [UIImage imageNamed:@"1"];
    }
    return _imageV;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
